package com.weme.common.manager

import account_server.v1.Account.GetGoodsListReply
import android.os.Handler
import android.os.Looper
import android.text.TextUtils
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import com.google.protobuf.ByteString
import com.jeremyliao.liveeventbus.LiveEventBus
import com.osom.proto.message.Brocast
import com.osom.proto.message.CommonOuterClass
import com.osom.proto.message.NetworkOuterClass
import com.weme.common.arouter.ARouterHelper
import com.weme.common.arouter.ARouterPaths
import com.weme.common.ext.filter
import com.weme.common.manager.SocketConnectManager.accountLiveData
import com.weme.common.network.*
import com.weme.common.socket.base.HandlerAdapter
import com.weme.common.util.*
import com.weme.common.util.AppMkHelper.CallConfigBean
import com.weme.common.util.LiveConfig.NET_WORK_BLACK
import com.weme.common.util.LiveConfig.NET_WORK_CALL
import com.weme.common.util.LiveConfig.NET_WORK_CALL_HISTORY
import com.weme.common.util.LiveConfig.NET_WORK_CALL_HISTORY_MATCH
import com.weme.common.util.LiveConfig.NET_WORK_CALL_HISTORY_MISSED
import com.weme.common.util.LiveConfig.NET_WORK_CHAT
import com.weme.common.util.LiveConfig.NET_WORK_ED_USER_IFNO
import com.weme.common.util.LiveConfig.NET_WORK_FANS
import com.weme.common.util.LiveConfig.NET_WORK_FOLLWING
import com.weme.common.util.LiveConfig.NET_WORK_GIFT
import com.weme.common.util.LiveConfig.NET_WORK_GOODS
import com.weme.common.util.LiveConfig.NET_WORK_HOME_HOT
import com.weme.common.util.LiveConfig.NET_WORK_HOME_NEW
import com.weme.common.util.LiveConfig.NET_WORK_LIVE
import com.weme.common.util.LiveConfig.NET_WORK_LIVE_EVALUATE
import com.weme.common.util.LiveConfig.NET_WORK_LOGIN
import com.weme.common.util.LiveConfig.NET_WORK_MATCHING
import com.weme.common.util.LiveConfig.NET_WORK_MATCH_NUMBER
import com.weme.common.util.LiveConfig.NET_WORK_MESSAGE
import com.weme.common.util.LiveConfig.NET_WORK_MESSAGE_ADD
import com.weme.common.util.LiveConfig.NET_WORK_MINE
import com.weme.common.util.LiveConfig.NET_WORK_SETTINGS
import com.weme.common.util.LiveConfig.NET_WORK_USER_IFNO
import com.weme.common.util.LiveConfig.NET_WORK_USER_LOOK_ALBUM
import dev.kratos.api.cms_server.v1.CallConfigReply
import dev.kratos.api.cms_server.v1.KeyValueConfigReply
import dev.kratos.api.im_server.v1.*
import dev.kratos.api.user_server.v1.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.java_websocket.handshake.ServerHandshake

/**
 * 消息处理的类
 *
 * @author
 */
class MessageHandler : HandlerAdapter {
    companion object {
        val TAG: String = "socket"
        private val lock = Object()
        var isCancelCall = false
        var cancelUid =0L
        fun setCancelCall(uid:Long){
            this.cancelUid = uid
            isCancelCall = true
            GlobalScope.launch {
                delay(3000)
                isCancelCall = false
                cancelUid = 0L
            }
        }
    }

    /**
     * 所有接受到的数据都会通过这个LiveData传递出去
     */
    private val innerReceiver: MutableLiveData<Any?> = MutableLiveData()
    private val foreverReceiver: MutableLiveData<Any?> = MutableLiveData()
    private val openService: MutableLiveData<Any?> = MutableLiveData()
    private val errorReceiver: MutableLiveData<NetworkOuterClass.Network> = MutableLiveData()

    /**
     * 所有接受到的数据都会通过这个LiveData传递出去
     */
    private val receiver = innerReceiver.filter {
        it != null
    }.map {
        it as Any
    }

    /**
     * Network数据会从这个传递出去
     */
    val netWorkReceiver = receiver.filter {
        it is NetworkOuterClass.Network
    }.map {
        it as NetworkOuterClass.Network
    }

    /**
     * 返回自己在在意的数据类型
     *
     * @param cmdId 在意的cmdId
     *
     * @param care 变换
     *
     * @author
     */
    fun <T> careReceiver(cmdId: Int, care: (ByteString) -> T): LiveData<T> {
        return netWorkReceiver.filter {
            cmdId == it.cmdid
        }.map {
            care(it.payload)
        }
    }

    override fun onOpen(handshakedata: ServerHandshake?) {
        Log.e(TAG, "socket 连接服务器成功")
        HeatBeat.sendHeatBeat()
        if (isdx) {
            handler.postDelayed({
                SocketManager.send(NetworkOuterClass.LoginRequest.newBuilder().setSession(UserMKHelper.decodeString(UserMKHelper.SESSION)).build(), NetworkOuterClass.NetworkCommand.CMD_GATEWAY_LOGIN_REQUEST.number, 0)
                Log.e(TAG, "socket 连接服务器成功1111111")
            }, 500)
        }

        openService.postValue("")
    }

    //var msgList: MutableList<Long> = ArrayList()

    override fun onMessage(message: String?) = Unit
    private val handler = Handler(Looper.getMainLooper())
    override fun onMessage(msg: Any?) {

            if (msg is NetworkOuterClass.Network) {
                if (msg.cmdid == NetworkOuterClass.NetworkCommand.CMD_GATEWAY_LOGIN_RESPONSE.number || msg.cmdid == NetworkOuterClass.NetworkCommand.CMD_GATEWAY_API_RESPONSE.number || msg.cmdid == NetworkOuterClass.NetworkCommand.CMD_GATEWAY_LOGINOUT_RESPONSE.number || msg.cmdid == NetworkOuterClass.NetworkCommand.CMD_GATEWAY_BROADCAST_REQUEST.number) {
                    if (msg.code != 0 && msg.messageseq != NetWorkUrl.CheckLogin.seq) {
                        Log.e("okhttp", "error" + msg.code + "/" + msg.cmdid + "/" + msg.messageseq)
                        when (msg.code) {
                            ERROR_CODE_NOT_SUBSCRIBE -> {//未订阅用户不能呼叫
                             LiveEventBus.get<Any>(NET_WORK_CALL).post(msg.code)
                            }
                            ERROR_CODE_CALLED_BUSY -> {//呼叫用户繁忙
                             LiveEventBus.get<Any>(NET_WORK_CALL).post(msg.code)
                            }
                            ERROR_CODE_CALL_BALANCE_NOT_ENOUGH -> {//呼叫失败余额不足
                             LiveEventBus.get<Any>(NET_WORK_CALL).post(msg.code)
                            }
                            ERROR_CODE_CHANNEL_NOT_EXIST->{//频道不存在
                             LiveEventBus.get<Any>(NET_WORK_CALL).post(CloseCallVideo())
                            }
                            ERROR_CODE_ANSWER_BALANCE_NOT_ENOUGH->{//接听失败余额不足AnswerVideo
                             LiveEventBus.get<Any>(NET_WORK_CALL).post(msg.code)
                            }
                            ERROR_CODE_USER_BALANCE_NOT_ENOUGH->{//用户余额不足
                             LiveEventBus.get<Any>(NET_WORK_MATCHING).post(msg.code)
                            }
                            CMD_VIDEO_CANCEL,ERROR_CODE_CALL_BUSY,ERROR_CODE_CALL_NOT_ONLINE,ERROR_COND_CALL_ONLINE,ERROR_CODE_CALL_WAIT,ERROR_CODE_CALL_FAIL ->{
                                UtilsApp.getTopActivity().showToast(msg.msg)
                             LiveEventBus.get<Any>(NET_WORK_CALL).post(CloseCallVideo())
                            }

                            else-> {
                                if(msg.messageseq == NetWorkUrl.HangUpVideo.seq){
                                    LiveEventBus.get<Any>(NET_WORK_LIVE).post(FinishLiveRoomActivity())
                                }
                                UtilsApp.getTopActivity().showToast(msg.msg)
                                msg.apply {
                                    errorReceiver.postValue(this)
                                }
                            }
                        }




                    } else {
                        synchronized(lock) {
                            handler.post { //                           foreverReceiver.postValue(msg)
                                //                           msgList.add(msg.messageseq)
                                msg.let { it ->
                                    try {
                                        if (it.cmdid == NetworkOuterClass.NetworkCommand.CMD_GATEWAY_API_RESPONSE.number) {
                                            val foundItem = enumValues<NetWorkUrl>().find { it.seq == msg.messageseq }
                                            Log.e(TAG, "NetworkCommand socket 收到消息" + msg.messageseq + " method = " + foundItem?.method)
                                            when (it.messageseq) {
                                                NetWorkUrl.Login.seq -> { // 处理 NetWorkUrl.Login.seq 特定逻辑
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val userLoginReply = UserLoginReply.parseFrom(data.data)
                                                    AppMkHelper.encode(AppMkHelper.LOGIN_LAST, 0)
                                                 LiveEventBus.get<Any>(NET_WORK_LOGIN).post(userLoginReply)
                                                }
                                                NetWorkUrl.GoogleLogin.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val userLoginReply = UserLoginReply.parseFrom(data.data)
                                                    AppMkHelper.encode(AppMkHelper.LOGIN_LAST, 1)
                                                 LiveEventBus.get<Any>(NET_WORK_LOGIN).post(userLoginReply)
                                                }
                                                NetWorkUrl.CheckLogin.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    if (data.data.size() == 0) {
                                                     LiveEventBus.get<Any>(NET_WORK_LOGIN).post(JumpLoginBean())
                                                        return@let
                                                    }
                                                    val checkLoginRequest = CheckLoginReply.parseFrom(data.data)

                                                    UserMKHelper.encode(UserMKHelper.UID, checkLoginRequest.user.uid)
                                                    UserMKHelper.encode(UserMKHelper.NAME, checkLoginRequest.user.nickname)
                                                    UserMKHelper.encode(UserMKHelper.HEADPIC, checkLoginRequest.user.headPic)
                                                    UserMKHelper.encode(UserMKHelper.AGE, checkLoginRequest.user.age)
                                                    //嘉城吧这个字段删了 不知道有没有其它问题
                                                    //   UserMKHelper.encode(UserMKHelper.VIP_LEVEL, checkLoginRequest.user.vipLevel)
                                                    UserMKHelper.encode(UserMKHelper.TOKEN, checkLoginRequest.token)
                                                    UserMKHelper.encode(UserMKHelper.COUNTRY_CODE, checkLoginRequest.user.countryCode)
                                                    UserMKHelper.encode(UserMKHelper.LANG, checkLoginRequest.user.lang)
                                                 LiveEventBus.get<Any>(NET_WORK_LOGIN).post(checkLoginRequest)
                                                }
                                                NetWorkUrl.KeyValueConfig.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val keyValueConfigRequest = KeyValueConfigReply.parseFrom(data.data)
                                                    val keyValues = keyValueConfigRequest.keyvaluesList
                                                    val loginType = keyValues.firstOrNull { it.key == LOGIN_TYPE }?.value
                                                    val bindType = keyValues.firstOrNull { it.key == BIND_TYPE }?.value
                                                    val matchTime = keyValues.firstOrNull { it.key == MATCH_TIME }?.value
                                                    val callWaitTime = keyValues.firstOrNull { it.key == CALL_WAIT_TIME }?.value
                                                    val rechargeGuide = keyValues.firstOrNull { it.key == RECHARGE_GUIDE }?.value
                                                    val feedbackTips = keyValues.firstOrNull { it.key == FEEDBACK_TIPS }?.value
                                                    val matchHallTips = keyValues.firstOrNull { it.key == MATCH_HALL_TIPS }?.value
                                                    val matchingTips = keyValues.firstOrNull { it.key == MATCHING_TIPS }?.value

                                                    AppMkHelper.encode(CALL_WAIT_TIME, callWaitTime)
                                                    AppMkHelper.encode(LOGIN_TYPE, loginType)
                                                    AppMkHelper.encode(BIND_TYPE, bindType)
                                                    AppMkHelper.encode(MATCH_TIME, matchTime)
                                                    AppMkHelper.encode(RECHARGE_GUIDE, rechargeGuide)
                                                    AppMkHelper.encode(FEEDBACK_TIPS, feedbackTips)
                                                    AppMkHelper.encode(MATCH_HALL_TIPS, matchHallTips)
                                                    AppMkHelper.encode(MATCHING_TIPS, matchingTips)

                                                    if (!TextUtils.isEmpty(UserMKHelper.decodeString(UserMKHelper.SESSION))) {
                                                     LiveEventBus.get<Any>(NET_WORK_LOGIN).post(keyValueConfigRequest)
                                                    } else {
                                                     LiveEventBus.get<Any>(NET_WORK_LOGIN).post(JumpLoginBean())
                                                    }
                                                }
                                                NetWorkUrl.CallConfig.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val callConfigReply = CallConfigReply.parseFrom(data.data)
                                                    AppMkHelper.encode(CallConfigBean, gson.toJson(callConfigReply.call))
                                                }
                                                NetWorkUrl.GetCountryList.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getCountryListReply = GetCountryListReply.parseFrom(data.data)
                                                    getCountryListReply.countryListList.forEach {
                                                        AppMkHelper.encode("country_${it.short}", gson.toJson(it))
                                                        Log.e("country", it.short.toString())
                                                    }
                                                    AppMkHelper.encode(AppMkHelper.COUNTRY_ALL, true)
                                                } //                    NetWorkUrl.GetAccountInfo.seq -> {
                                                //                        val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                //                        Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                //                        val getAccountInfoRequest = GetAccountInfoReply.parseFrom(data.data)
                                                //                     LiveEventBus.get<Any>(NET_WORK_HOME).post(getAccountInfoRequest)
                                                //                    }
                                                NetWorkUrl.GetAccountInfo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getAccountInfoRequest = GetAccountInfoReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_MINE).post(getAccountInfoRequest)
                                                }
                                                NetWorkUrl.OnlineList.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    if (data.data.isEmpty) {
                                                     LiveEventBus.get<Any>(NET_WORK_HOME_HOT).post(OnLineErrorBean())
                                                        return@let
                                                    }
                                                    val getOnlineListReply = GetOnlineListReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_HOME_HOT).post(getOnlineListReply)
                                                }
                                                NetWorkUrl.OnlineNewList.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    if (data.data.isEmpty) {
                                                     LiveEventBus.get<Any>(NET_WORK_HOME_NEW).post(OnLineErrorBean())
                                                        return@let
                                                    }
                                                    val getOnlineListReply = GetOnlineListReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_HOME_NEW).post(getOnlineListReply)
                                                }
                                                NetWorkUrl.GetUserInfo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getUserInfoReply = GetUserInfoReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_MESSAGE).post(getUserInfoReply)
                                                }
                                                NetWorkUrl.AddUserInfo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getUserInfoReply = GetUserInfoReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_MESSAGE_ADD).post(getUserInfoReply)
                                                }

                                                NetWorkUrl.Bind.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getUserInfoReply = GetUserInfoReply.parseFrom(data.data) //uid类型 0游客id未绑定,1游客id已绑定,2游客通过fb谷歌注册自动完成绑定,3绑定ID已经删除
                                                    val userlist = getUserInfoReply.usersList.firstOrNull()
                                                    userlist?.let {
                                                     LiveEventBus.get<Any>(NET_WORK_MINE).post(it)
                                                    }
                                                }
                                                NetWorkUrl.MineGetUserInfo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getUserInfoReply = GetUserInfoReply.parseFrom(data.data) //uid类型 0游客id未绑定,1游客id已绑定,2游客通过fb谷歌注册自动完成绑定,3绑定ID已经删除
                                                    val userlist = getUserInfoReply.usersList.firstOrNull()
                                                    userlist?.let {
                                                     LiveEventBus.get<Any>(NET_WORK_MINE).post(it)
                                                    }

                                                }
                                                NetWorkUrl.GetVipInfo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getVipInfoReply = GetVipInfoReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_MINE).post(getVipInfoReply)
                                                }
                                                NetWorkUrl.GetFollowCount.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getFollowCountReply = GetFollowCountReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_MINE).post(getFollowCountReply)
                                                    Log.e("socket", "我关注了" + getFollowCountReply.followCount.toString() + "人")

                                                }
                                                NetWorkUrl.GetFansCount.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getFansCountRequest = GetFansCountReply.parseFrom(data.data)
                                                    Log.e("socket", "有" + getFansCountRequest.fansCount.toString() + "关注了我")
                                                 LiveEventBus.get<Any>(NET_WORK_MINE).post(getFansCountRequest)
                                                }

                                                NetWorkUrl.GetUserInfoIn.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getUserInfoReply = GetUserInfoReply.parseFrom(data.data)
                                                    val userlist = getUserInfoReply.usersList.firstOrNull()
                                                    userlist?.let {
                                                     LiveEventBus.get<Any>(NET_WORK_ED_USER_IFNO).post(it)
                                                    }
                                                }
                                                NetWorkUrl.UploadAlbum.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val uploadAlbumReply = UploadAlbumReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_ED_USER_IFNO).post(uploadAlbumReply)
                                                }
                                                NetWorkUrl.GetAlbum.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getAlbumReply = GetAlbumReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_ED_USER_IFNO).post(getAlbumReply)
                                                }
                                                NetWorkUrl.Follow.seq -> {
                                                    if (it.code == 0) {
                                                     LiveEventBus.get<Any>(NET_WORK_USER_IFNO).post(FollowBean(true))
                                                    } else {
                                                        UtilsApp.getTopActivity().showToast(it.msg)
                                                    }
                                                }
                                                NetWorkUrl.UnFollow.seq -> {
                                                    if (it.code == 0) {
                                                     LiveEventBus.get<Any>(NET_WORK_USER_IFNO).post(FollowBean(false))
                                                    } else {
                                                        UtilsApp.getTopActivity().showToast(it.msg)
                                                    }
                                                }
                                                NetWorkUrl.GetUserInfoUserInfo.seq, NetWorkUrl.GetUserInfoActivity.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)

                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getUserInfoReply = GetUserInfoReply.parseFrom(data.data)
                                                    val userlist = getUserInfoReply.usersList.firstOrNull()
                                                    userlist?.let {
                                                     LiveEventBus.get<Any>(NET_WORK_USER_IFNO).post(it)
                                                    }
                                                }
                                                NetWorkUrl.UserInfoAlbum.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getAlbumReply = GetAlbumReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_USER_IFNO).post(getAlbumReply)
                                                }
                                                NetWorkUrl.SendGiftUserInfo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val sendGiftReply = SendGiftReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_USER_IFNO).post(sendGiftReply)
                                                }


                                                NetWorkUrl.Logout.seq -> {
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${it.payload.toStringUtf8()} ")
                                                 LiveEventBus.get<Any>(NET_WORK_SETTINGS).post(OutLoginBean(false))
                                                }

                                                NetWorkUrl.GetChatAlbum.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getAlbumReply = GetAlbumReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CHAT).post(getAlbumReply)
                                                }
                                                NetWorkUrl.SendChatGift.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val sendGiftRequest = SendGiftReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CHAT).post(sendGiftRequest)

                                                }

                                                NetWorkUrl.ChatUserInfo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getUserInfoReply = GetUserInfoReply.parseFrom(data.data)
                                                    val userlist = getUserInfoReply.usersList.firstOrNull()
                                                    userlist?.let {
                                                     LiveEventBus.get<Any>(NET_WORK_CHAT).post(it)
                                                    }

                                                }

                                                NetWorkUrl.FollowList.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val followListReply = FollowListReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_FOLLWING).post(followListReply)
                                                }


                                                NetWorkUrl.DeleteAlbum.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getAlbumReply = DeleteAlbumReply.parseFrom(data.data)
                                                    Log.e("okhttp", getAlbumReply.toString())
                                                    if (it.code == 0) {
                                                        UtilsApp.getTopActivity().showToast(UtilsApp.getTopActivity().getString(com.example.resources.R.string.toast_success))
                                                    }
                                                }
                                                NetWorkUrl.SendGiftLookBigImg.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val sendGiftReply = SendGiftReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_USER_LOOK_ALBUM).post(sendGiftReply)
                                                }
                                                NetWorkUrl.LookImgReport.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val reportReply = ReportReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_USER_LOOK_ALBUM).post(reportReply)
                                                }


                                                NetWorkUrl.DeleteAccount.seq -> {
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${it.payload.toStringUtf8()} ")
                                                    UtilsApp.outLogin()
                                                    ARouterHelper.navigateToActivity(UtilsApp.getTopActivity(), ARouterPaths.LOGIN_ACTIVITY)
                                                }
                                                NetWorkUrl.FansList.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val followListReply = FollowListReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_FANS).post(followListReply)
                                                }
                                                NetWorkUrl.GetGiftList.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getGiftListReply = GetGiftListReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_GIFT).post(getGiftListReply)
                                                }
                                                NetWorkUrl.GetMatchBanner.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息123123123123 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getMatchBannerReply = GetMatchBannerReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_MATCHING).post(getMatchBannerReply)
                                                }
                                                NetWorkUrl.MatchRequest.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val matchReply = MatchReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_MATCHING).post(matchReply)
                                                }
                                                NetWorkUrl.MatchCancelRequest.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val matchCancelReply = MatchCancelReply.parseFrom(data.data)
                                                    Log.e("socket", "匹配id=" + matchCancelReply.matchId)
                                                 LiveEventBus.get<Any>(NET_WORK_MATCHING).post(matchCancelReply)
                                                }
                                                NetWorkUrl.GetRtcToken.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getRtcTokenReply = GetRtcTokenReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_LIVE).post(getRtcTokenReply)
                                                }
                                                NetWorkUrl.LiveFollow.seq -> {
                                                    if (it.code == 0) {
                                                        LiveEventBus.get<Any>(NET_WORK_LIVE).post(FollowBean(true))
                                                    } else {
                                                        UtilsApp.getTopActivity().showToast(it.msg)
                                                    }
                                                }
                                                NetWorkUrl.HangUpVideo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val hangUpVideoReply = HangUpVideoReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_LIVE).post(hangUpVideoReply)
                                                }
                                                NetWorkUrl.CallVideo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val callVideoReply = CallVideoReply.parseFrom(data.data)
                                                    Log.e("socket","3333333333333333"+isCancelCall)
                                                    if(isCancelCall){
                                                     LiveEventBus.get<Any>(LiveConfig.NET_COSTOM_MSG).post(CallSuspendCancel(callVideoReply.channelName))
                                                    }else{
                                                     LiveEventBus.get<Any>(NET_WORK_CALL).post(callVideoReply)
                                                    }
                                                    //修改逻辑 进发起通话 在调接口
                                                    //callVideoLiveData.postValue(callVideoReply)

                                                }
                                                NetWorkUrl.GetCallUserInfo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val getUserInfoReply = GetUserInfoReply.parseFrom(data.data)
                                                    val userlist = getUserInfoReply.usersList.firstOrNull()
                                                    userlist?.let {
                                                     LiveEventBus.get<Any>(NET_WORK_CALL).post(it)
                                                    }

                                                }
                                                NetWorkUrl.AnswerVideo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${this::class.java.simpleName} payload=${data.data.toStringUtf8()} ")
                                                    val answerReply = AnswerVideoReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CALL).post(answerReply)
                                                }
                                                NetWorkUrl.LiveGetUserInfo.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val getUserInfoReply = GetUserInfoReply.parseFrom(data.data)
                                                    val userlist = getUserInfoReply.usersList.firstOrNull()
                                                    userlist?.let {
                                                     LiveEventBus.get<Any>(NET_WORK_LIVE).post(it)
                                                    }
                                                }
                                                NetWorkUrl.CallGetAlbum.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val getAlbumReply = GetAlbumReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CALL).post(getAlbumReply)
                                                }
                                                NetWorkUrl.GetGiftWall.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val getGiftWallReply = GetGiftWallReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_USER_IFNO).post(getGiftWallReply)
                                                }
                                                NetWorkUrl.GetGoodsList.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val getGoodsListReply = GetGoodsListReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_GOODS).post(getGoodsListReply)
                                                }
                                                NetWorkUrl.SendGiftLive.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val sendGiftReply = SendGiftReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_LIVE).post(sendGiftReply)
                                                }
                                                NetWorkUrl.CallEvaluate.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val sendGiftReply = CallEvaluateRequest.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_LIVE_EVALUATE).post(sendGiftReply)
                                                }
                                                NetWorkUrl.GetCallRecord.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val sendGiftReply = GetCallRecordReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CALL_HISTORY).post(sendGiftReply)
                                                }
                                                NetWorkUrl.GetCallRecordMissed.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val sendGiftReply = GetCallRecordReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CALL_HISTORY_MISSED).post(sendGiftReply)
                                                }
                                                NetWorkUrl.GetCallRecordMatch.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val sendGiftReply = GetCallRecordReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CALL_HISTORY_MATCH).post(sendGiftReply)
                                                }
                                                NetWorkUrl.Black.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")

                                                    val blackReply = BlackReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CHAT).post(blackReply)
                                                }
                                                NetWorkUrl.UnBlack.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val unBlackReply = UnBlackReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CHAT).post(unBlackReply)

                                                }
                                                NetWorkUrl.Report.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val reportReply = ReportReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CHAT).post(reportReply)
                                                }
                                                NetWorkUrl.Translate.seq->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val translateReply = TranslateReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CHAT).post(translateReply)
                                                }
                                                NetWorkUrl.LiveTranslate.seq->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val translateReply = TranslateReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_LIVE).post(translateReply)
                                                }

                                                NetWorkUrl.GetBlackList.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val getBlackListReply = GetBlackListReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_BLACK).post(getBlackListReply)
                                                }
                                                NetWorkUrl.Feedback.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val feedbackReply = FeedbackReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_BLACK).post(feedbackReply)

                                                }
                                                NetWorkUrl.RefuseVideo.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val refuseReply = RefuseVideoReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CALL).post(refuseReply)
                                                }
                                                NetWorkUrl.GetChannelInfo.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val getChannelInfoReply = GetChannelInfoReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_LIVE).post(getChannelInfoReply)
                                                }
                                                NetWorkUrl.CallGetChannelInfo.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val getChannelInfoReply = GetChannelInfoReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CALL).post(getChannelInfoReply)
                                                }
                                                NetWorkUrl.DownloadGiftMp4.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val getGiftListReply = GetGiftListReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_MINE).post(getGiftListReply)
                                                }
                                                NetWorkUrl.DownloadGiftMp4.seq ->{
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val getGiftListReply = GetGiftListReply.parseFrom(data.data)
                                                 LiveEventBus.get<Any>(NET_WORK_MINE).post(getGiftListReply)
                                                }
                                                NetWorkUrl.CheckBlack.seq -> {
                                                    val data = CommonOuterClass.BaseResponse.parseFrom(it.payload)
                                                    Log.e("socket", "call <- 接收消息 seq=${it.messageseq} ${it.serverName} payload=${data.data.toStringUtf8()} +num = ${it.subversion}")
                                                    val checkBlackReply = CheckBlackReply.parseFrom(data.data)
                                                    Log.e("socket",checkBlackReply.toString())
                                                 LiveEventBus.get<Any>(LiveConfig.NET_USER_INFO_AROUTER).post(checkBlackReply)
                                                }


                                            }
                                        } else if ( it.cmdid == NetworkOuterClass.NetworkCommand.CMD_GATEWAY_LOGIN_RESPONSE.number) { //       showToast("google或游客请求登录服务器成功")
                                         LiveEventBus.get<Any>(NET_WORK_LOGIN).post(JumpMainBean())
                                        } else if (it.cmdid == NetworkOuterClass.NetworkCommand.CMD_GATEWAY_LOGINOUT_RESPONSE.number) {
                                         LiveEventBus.get<Any>(NET_WORK_SETTINGS).post(OutLoginBean(true))
                                        } else if ( it.cmdid == NetworkOuterClass.NetworkCommand.CMD_GATEWAY_BROADCAST_REQUEST.number) { //  val data = CommonOuterClass.BrocastResponse.parseFrom(it.payload)
                                            val brocast = Brocast.BrocastResponse.parseFrom(it.payload)
                                            val foundItem = enumValues<Brocast.BrocastId>().find { it.number == brocast.id }
                                            Log.e("socket", "BrocastResponse call <- 收到推送消息 ${brocast.id}&${foundItem?.name} payload=${it.payload.toStringUtf8()} "+System.currentTimeMillis())

                                            when (brocast.id) {
                                                Brocast.BrocastId.CMD_UPDATE_ACCOUNT.number -> {
                                                    val accouts = Accounts.parseFrom(brocast.data)
                                                    accountLiveData.postValue(accouts)

                                                    Log.e("socket", "call <- 收到推送消息  payload=${accouts} ")
                                                }
                                                Brocast.BrocastId.CMD_KICKOUT.number -> {
                                                    UtilsApp.outLogin()
                                                    ARouterHelper.navigateToActivity(UtilsApp.getTopActivity(), ARouterPaths.LOGIN_ACTIVITY)
                                                }
                                                Brocast.BrocastId.CMD_MATCH_TIMEOUT.number -> { //匹配超时


                                                    val matchMessage = Brocast.MatchMessage.parseFrom(brocast.data)
                                                 LiveEventBus.get<Any>(Brocast.BrocastId.CMD_MATCH_TIMEOUT.name).post(matchMessage)
                                                }
                                                Brocast.BrocastId.CMD_MATCH_ANSWER.number -> { //匹配应答
                                                    val matchMessage = Brocast.MatchMessage.parseFrom(brocast.data)
                                                 LiveEventBus.get<Any>(Brocast.BrocastId.CMD_MATCH_ANSWER.name).post(matchMessage)
                                                } //                                   Brocast.BrocastId.CMD_MATCH_DISPATCH.number -> {//匹配派单
                                                //                                       val matchMessage = Brocast.MatchMessage.parseFrom(brocast.data)
                                                //
                                                //                                   }
                                                Brocast.BrocastId.CMD_MATCH_CANCEL.number -> { //匹配取消
                                                 LiveEventBus.get<Any>(Brocast.BrocastId.CMD_MATCH_TIMEOUT.name).post(brocast.id)
                                                }
                                                Brocast.BrocastId.CMD_VIDEO_CALL.number -> { //拨打视频电话
                                                    val matchMessage = Brocast.VideoCallMessage.parseFrom(brocast.data)
                                                    SocketConnectManager.callLiveData.postValue(matchMessage)

                                                }



                                                Brocast.BrocastId.CMD_VIDEO_ANSWER.number -> { //视频电话接听  拨打视频电话被接听
                                                    val videoCallMessage = Brocast.VideoCallMessage.parseFrom(brocast.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CALL).post(videoCallMessage)
                                                }
                                                Brocast.BrocastId.CMD_VIDEO_REJECT.number -> { //视频电话拒绝
                                                 LiveEventBus.get<Any>(NET_WORK_CALL).post(VideoCallEndReasonBean())

                                                }
                                                Brocast.BrocastId.CMD_VIDEO_HANGUP.number -> { //视频电话挂断
                                                    val hangUpVideoReply = HangUpVideoReply.parseFrom(brocast.data)
                                                 LiveEventBus.get<Any>(NET_WORK_CALL).post(hangUpVideoReply)
                                                }
                                                Brocast.BrocastId.CMD_MATCH_COUNT.number -> { //匹配人数通知
                                                    val matchCount = Brocast.MatchCount.parseFrom(brocast.data)
                                                 LiveEventBus.get<Any>(NET_WORK_MATCH_NUMBER).post(matchCount)
                                                }
                                                Brocast.BrocastId.CMD_VIDEO_KICKOUT.number ->{//匹配取消

                                                 LiveEventBus.get<Any>(NET_WORK_CALL).post(MatchCancel())
                                                }
                                                Brocast.BrocastId.CMD_VIDEO_CANCEL.number -> { //视频取消
                                                 LiveEventBus.get<Any>(NET_WORK_CALL).post(CallCancel())

                                                }

                                            }

                                        }
                                    }catch (e:Exception){}


                                }
                            }
                        }
                        HeatBeat.sendHeatBeat()

                    }

                }
            }




        //   innerReceiver.postValue(msg)


    }



    fun getForeverReceiver(): MutableLiveData<Any?> {
        return foreverReceiver
    }

    fun getOpenService(): MutableLiveData<Any?> {
        return openService
    }

    fun getErrorService(): MutableLiveData<NetworkOuterClass.Network> {
        return errorReceiver
    }


    override fun onClose(code: Int, reason: String?, remote: Boolean) {
        Log.e(TAG, "socket 连接关闭 错误码:$code,错误原因:$reason") //   if (code != CloseFrame.NORMAL) {
        //非正常关闭，开启重连
        isdx = true
        SocketConnectManager.startReConnect(true) // }
    }

    var isdx = false

    override fun onError(ex: Exception?) {
        Log.e(TAG,"onError"+ Log.getStackTraceString(ex)) //非正常关闭，开启重连
        isdx = true
        SocketConnectManager.startReConnect(true)
    }
}